#include <queue>
#include <stdexcept>

template <typename T>
class PakcetBuffer
{
public:
	PakcetBuffer(size_t maxSize = 0);
	bool bufferPacket(const T& packet);
	T getNextPacket() throw(std::out_of_range);

protected:
	std::queue<T> mPackets;
	int mMaxSize;
};

template <typename T>
PakcetBuffer<T>::PakcetBuffer(size_t maxSize /* = 0 */) : mMaxSize(maxSize)
{

}

template <typename T>
bool PakcetBuffer<T>::bufferPacket(const T& packet)
{
	if(mMaxSize > 0 && mPackets.size() == mMaxSize)
		return false;

	mPackets.push(packet);
	return true;
}

template<typename T>
T PakcetBuffer<T>::getNextPacket() throw (std::out_of_range)
{
	if (mPackets.empty())
	{
		throw std::out_of_range("Buffer is empty");
	}

	T temp = mPackets.front();
	mPackets.pop();

	return temp;
}